package com.ymatou.iapi.godmch.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.editmchBean;
import com.ymatou.iapi.godmch.parameter.getMchIdListByMchTitleBean;
import com.ymatou.iapi.godmch.service.getMchIdListByMchTitleCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.mch_info;
import com.ymttest.database.sqlwapper.godmch.country_infoWapper;
import com.ymttest.database.sqlwapper.godmch.mch_infoWapper;
import com.ymttest.utils.TestDataManager;
/**
*商户名称获取商户id列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getMchIdListByMchTitle{
	private static getMchIdListByMchTitleBean bean;
	private static getMchIdListByMchTitleCall call;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商户名称获取商户id列表");
	}

	@Before
	public void caseUp() {
		bean=new getMchIdListByMchTitleBean();
		call=new getMchIdListByMchTitleCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchIdListByMchTitle_001() {
		Logger.start(true,"正例-商户名称获取商户id列表");
		try {
			//渠道
			UserCreateBean usercreateBean1=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean1);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			editmchBean editmchbean = GodmchManageCallService.IniteditmachBean(userId_channl);
			GodmchManageCallService.editmachCall(editmchbean);
			
			bean.setMchTitle(editmchbean.getMchTitle());
			call.setData(bean);
			call.callService();			

			Logger.verifyEquals("200", call.getStatus1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
        	int mchId1=call.getmchIdList().get(0).getAsInt();
        	Logger.verifyEquals(userId_channl, mchId1, "验证返回成功mchId值");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchIdListByMchTitle_002() {
		Logger.start(true,"正例-商户名称获取商户id列表-两个相同的商户名称");
		try {
			String title="两个相同的商户名称"+new TestDataManager().getRandomIntNum(6);
			//渠道1
			UserCreateBean usercreateBean1=DGUserCallService.initSellerUsercreateBean();
			int userId_channl1=DGUserCallService.UserCreateCall(usercreateBean1);
			//渠道2
			UserCreateBean usercreateBean2=DGUserCallService.initSellerUsercreateBean();
			int userId_channl2=DGUserCallService.UserCreateCall(usercreateBean2);
			//创建
			createmchBean createmchbean1=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl1);
			GodmchManageCallService.createmchCallForChannel(createmchbean1);
			editmchBean editmchbean1 = GodmchManageCallService.IniteditmachBean(userId_channl1);
			editmchbean1.setMchTitle(title);
			GodmchManageCallService.editmachCall(editmchbean1);
			
			createmchBean createmchbean2=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl2);
			GodmchManageCallService.createmchCallForChannel(createmchbean2);
			editmchBean editmchbean2 = GodmchManageCallService.IniteditmachBean(userId_channl2);
			editmchbean2.setMchTitle(title);
			GodmchManageCallService.editmachCall(editmchbean2);
			
			bean.setMchTitle(editmchbean1.getMchTitle());
			call.setData(bean);
			call.callService();			

			Logger.verifyEquals("200", call.getStatus1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
        	int mchId1=call.getmchIdList().get(0).getAsInt();
        	int mchId2=call.getmchIdList().get(1).getAsInt();
        	Logger.verifyEquals(userId_channl1, mchId1, "验证返回第一个mchId值");
        	Logger.verifyEquals(userId_channl2, mchId2, "验证返回第二个mchId值");
        	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchIdListByMchTitle_003() {
		Logger.start(true,"正例-商户名称获取商户id列表-没有匹配的商户名称");
		try {
			bean.setMchTitle("没有匹配的商户名称");
			call.setData(bean);
			call.callService();			

			Logger.verifyEquals("200", call.getStatus1(), "验证返回成功status值");
	        Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");	
	        Logger.verifyEquals(0, call.getmchIdList().size(), "验证返回的mchIdList为空");
	        
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getMchIdListByMchTitle_004() {
		Logger.start(true,"正例-商户名称获取商户id列表-mchTitle为空");
		try {
			bean.setMchTitle("");
			call.setData(bean);
			call.callService();			

			Logger.verifyEquals("4001", call.getStatus1(), "验证返回参数异常");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}